<template>
	<view class="page">
		<pageTxt>
			<!--  v-model="dataList" @query="queryList" -->
			<z-paging ref="paging" refresher-only @onRefresh="onRefresh" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<u-navbar title="设计详情" :autoBack="true" :fixed="false"></u-navbar>
					<view class="tab-box">
						<u-tabs
							:current="tabIndex"
							@click="tabClickFunc"
							:list="tablist"
							inactiveStyle="color: #919092;"
							activeStyle="color: #3B75FF;"
							lineColor="#3B75FF"
						></u-tabs>
					</view>
				</template>
				<!-- 内容 -->
				<view class="detail-content-box" v-if="dataObj">
					<template v-if="tabIndex == 0">
						<u-empty
							v-if="!$fieldShowFunc('32-xmxx') && !$fieldShowFunc('32-sjtxx')"
							marginTop="300rpx"
							icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png"
							text=" "
						></u-empty>
						<view class="item-box" v-if="$fieldShowFunc('32-xmxx')">
							<view class="title">项目信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_xmmc')">
								<text class="txt">项目名称</text>
								<view class="content">
									{{ dataObj.project_name }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_xmbh')">
								<text class="txt">项目编号</text>
								<view class="content">
									<text class="txt-btn" @click="navToProjectFunc">
										{{ dataObj.project_number || '--' }}
									</text>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_xmpp')">
								<text class="txt">项目品牌</text>
								<view class="content">
									{{ dataObj.brand_name }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_xmlx')">
								<text class="txt">项目类型</text>
								<view class="content">
									{{ dataObj.store_type_name }}
								</view>
							</view>
						</view>
						<view class="item-box" v-if="$fieldShowFunc('32-sjtxx')">
							<view class="title">设计图信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_pmtwj')">
								<text class="txt">平面图文件</text>
								<view class="content flex ac flex">
									<image
										v-for="(item, idx) in dataObj.project_file.plan_drawing"
										:key="idx"
										:src="$fileImgFunc(item)"
										@click="previewFunc(item)"
										mode="aspectFill"
										class="img-box"
									></image>
									<template v-if="!dataObj.project_file.plan_drawing.length">--</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_xgtwj')">
								<text class="txt">效果图文件</text>
								<view class="content flex ac flex">
									<image
										v-for="(item, idx) in dataObj.project_file.effect_drawing"
										:key="idx"
										:src="$fileImgFunc(item)"
										@click="previewFunc(item)"
										mode="aspectFill"
										class="img-box"
									></image>
									<template v-if="!dataObj.project_file.effect_drawing.length">--</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_sgtwj')">
								<text class="txt">施工图文件</text>
								<view class="content flex ac flex">
									<image
										v-for="(item, idx) in dataObj.project_file.construction_drawing"
										:key="idx"
										:src="$fileImgFunc(item)"
										@click="previewFunc(item)"
										mode="aspectFill"
										class="img-box"
									></image>
									<template v-if="!dataObj.project_file.construction_drawing.length">--</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sj_qtwj')">
								<text class="txt">其他文件</text>
								<view class="content flex ac flex">
									<image
										v-for="(item, idx) in dataObj.project_file.other_file"
										:key="idx"
										:src="$fileImgFunc(item)"
										@click="previewFunc(item)"
										mode="aspectFill"
										class="img-box"
									></image>
									<template v-if="!dataObj.project_file.other_file.length">--</template>
								</view>
							</view>
						</view>
					</template>
					<!-- 历史 -->
					<template v-if="tabIndex == 1">
						<view class="item-box">
							<u-empty v-if="!logList.length" marginTop="300rpx" icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png" text=" "></u-empty>
							<u-steps current="0" direction="column" dot activeColor="#3b75ff" inactiveColor="#3b75ff">
								<u-steps-item v-for="(item, index) in logList" :key="index">
									<template slot="desc">
										<view class="steps-title flex ac jb">
											<view class="steps-title-title">{{ item.updated_at }}</view>
											<view class="steps-title-user-data-box flex ac jc">
												<image class="avater-box" :src="item.handlers_image" mode="aspectFit"></image>
												<view class="user-name u-line-1">
													{{ item.handlers_name + '-' + item.handlers_position }}
												</view>
											</view>
										</view>
										<view class="steps-desc">
											<view class="steps-desc-title">
												{{ item.content }}
											</view>
											<template v-if="item.form_data.plan_drawing.length && $fieldShowFunc('sj_pmtwj')">
												<view class="steps-desc-box">
													<view class="steps-desc-box-title">平面图文件</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<view class="img-box" v-for="(file, fileIndex) in item.form_data.plan_drawing" :key="fileIndex">
															<view v-if="file.delete" class="del-box">Del</view>
															<image @click="previewFunc(file)" :src="$fileImgFunc(file)"></image>
														</view>
													</view>
												</view>
											</template>
											<template v-if="item.form_data.effect_drawing.length && $fieldShowFunc('sj_xgtwj')">
												<view class="steps-desc-box">
													<view class="steps-desc-box-title">效果图文件</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<view class="img-box" v-for="(file, fileIndex) in item.form_data.effect_drawing" :key="fileIndex">
															<view v-if="file.delete" class="del-box">Del</view>
															<image @click="previewFunc(file)" :src="$fileImgFunc(file)"></image>
														</view>
													</view>
												</view>
											</template>
											<template v-if="item.form_data.construction_drawing.length && $fieldShowFunc('sj_sgtwj')">
												<view class="steps-desc-box">
													<view class="steps-desc-box-title">施工图文件</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<view class="img-box" v-for="(file, fileIndex) in item.form_data.construction_drawing" :key="fileIndex">
															<view v-if="file.delete" class="del-box">Del</view>
															<image @click="previewFunc(file)" :src="$fileImgFunc(file)"></image>
														</view>
													</view>
												</view>
											</template>
											<template v-if="item.form_data.other_file.length && $fieldShowFunc('sj_qtwj')">
												<view class="steps-desc-box">
													<view class="steps-desc-box-title">其他文件</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<view class="img-box" v-for="(file, fileIndex) in item.form_data.other_file" :key="fileIndex">
															<view v-if="file.delete" class="del-box">Del</view>
															<image @click="previewFunc(file)" :src="$fileImgFunc(file)"></image>
														</view>
													</view>
												</view>
											</template>
										</view>
									</template>
								</u-steps-item>
							</u-steps>
						</view>
					</template>
				</view>
				<view class="bottom-btn-box flex ac jb" slot="bottom">
					<view style="width: 100%" v-if="!loading">
						<judgeBtn info unborder :per_arr="per_arr" objectType="payment" :btns="btns" :state="dataObj.status" :item="dataObj" @change="btnsChange"></judgeBtn>
					</view>
				</view>
			</z-paging>
		</pageTxt>
		<!-- 文件预览 -->
		<preFileCom :fileObj="fileObj" @onFileSuccess="fileObj = ''"></preFileCom>
		<!-- 操作组件 -->
		<designOperate :value.sync="per_name" :oper_item="oper_item" @submit="handleSubmit"></designOperate>
	</view>
</template>

<script>
export default {
	provide() {
		return {
			providedData: this.btns
		};
	},
	data() {
		return {
			fileObj: '',
			loading: false,
			logList: [],
			dataObj: '',
			tabIndex: 0,
			tablist: [
				{
					name: '详情'
				},
				{
					name: '历史记录'
				}
			],
			per_arr: [], //权限列表
			// 操作按钮
			btns: [
				{
					per_name: 'design_img',
					func: (item) => {
						if (item.status == 1060 || item.status == 1015) {
							return true;
						} else {
							return false;
						}
					},
					name: '上传图纸'
				},
				{
					per_name: 'projects_updDesignDrawings',
					func: (item) => {
						if (
							item.project_file.construction_drawing.length != 0 ||
							item.project_file.construction_drawing_image.length != 0 ||
							item.project_file.effect_drawing.length != 0 ||
							item.project_file.effect_drawing_image.length != 0 ||
							item.project_file.other_file.length != 0 ||
							item.project_file.plan_drawing.length != 0 ||
							item.project_file.plan_drawing_image.length != 0
						) {
							return true;
						} else {
							return false;
						}
					},
					name: '重新上传图纸'
				}
			],
			// 操作相关
			per_name: '',
			oper_item: {}
		};
	},
	onLoad(option) {
		this.designProjectDetails(option.id);
		// 获取权限
		this.$Api
			.getHtmlAuthority({
				path: '/designManagement'
			})
			.then((res) => {
				console.log(res, 'getHtmlAuthority');
				if (res.code == 200) {
					this.per_arr = res.data.permission;
				}
			});
	},
	onShow() {
		if (!this.dataObj) return;
		this.designProjectDetails(this.dataObj.id);
	},
	methods: {
		// 操作反馈
		handleSubmit(e) {
			this.onRefresh();
		},
		// 操作事件
		btnsChange(e) {
			console.log(e);
			this.per_name = e.per_name;
			this.oper_item = e.item;
		},
		onRefresh() {
			this.designProjectDetails(this.dataObj.id);
			this.$refs.paging.complete();
		},
		tabClickFunc(e) {
			this.tabIndex = e.index;
		},
		// 详情
		designProjectDetails(project_id) {
			this.loading = true;
			this.$Apipc
				.designProjectDetails({
					project_id
				})
				.then((res) => {
					console.log(res, '设计详情');
					this.loading = false;
					if (res.code == 200) {
						res.data.log_list.forEach((item) => {
							item.form_data = JSON.parse(item.form_data);
							if (item.form_data.delete_arr) {
								item.form_data.delete_arr.forEach((child) => {
									if (item.form_data[child.type]) {
										item.form_data[child.type].push(child);
									}
								});
							}
						});
						this.logList = res.data.log_list;
						this.dataObj = res.data;
					}
				});
		},
		// 预览
		previewFunc(item) {
			this.fileObj = item;
		},
		// 去详情项目
		navToProjectFunc() {
			uni.navigateTo({
				url: '/pagesB/projectDetail/projectDetail?id=' + this.dataObj.id
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
